// pages/feedback/feedback.js
var app = getApp(), fetchApi = require("../../utils/httpPost.js");
const { default: Toast } = require("../../component/vant/toast/toast.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    content: "",
    phoneNumber: ""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  formSubmit:function(e){
    var t = e.detail.value.textarea.trim(), o = e.detail.value.iphone, n = !1, c = /^[1][3,4,5,7,8][0-9]{9}$/, i = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
    if (n = /^[0-9]+.?[0-9]*$/.test(o) ? this.checkPhoneNum(c, "请输入正确的手机号", o) : this.checkPhoneNum(i, "请输入正确的微信号", o),
      "" == t || "" == o) wx.showModal({
        title: "温馨提示",
        content: "请输入完整信息！",
        showCancel: !1
      });
      else if (n) {
        if (t == this.data.content) return;
        this.setData({
          content: t,
          phoneNumber: o
        }), this.feedback(t, o);
      }
  },
  feedback: function (e, o){
    var that = this
    fetchApi.httpPost('/user/addFeedback', {
      phone_num: that.data.phoneNumber,
      content: that.data.content
    }, function (res) {
      console.log("提交反馈返回数据", e)
      if (res.data.code == 0) {
        wx.showModal({
          title: "温馨提示",
          content: "谢谢您的反馈",
          confirmText: "我知道了",
          showCancel: !1,
          success: function (e) {
            e.confirm && wx.switchTab({
              url: "/pages/personal/index"
            });
          }
        })
      } else {
        Toast.fail(res.data.msg)
      }
    },function(){})
  },
  checkPhoneNum: function (e, t, o) {
    return !("" != o && !e.test(o)) || (wx.showToast({
      title: t,
      icon: "none",
      duration: 1500
    }), !1);
  },
})